﻿Imports System.Data.SqlClient

Public Class AdminAddUser
    Inherits System.Web.UI.Page
    Dim p As New DocGia_DTO()
    Dim docgia As New DocGia_BLL()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Session("hinhanh") = String.Empty
        End If
    End Sub

    Protected Sub btn_xacnhan_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_xacnhan.Click
        Try
            p._taikhoan = dtxt_taikhoan.Text
            p._matkhau = dtxt_rematkhau.Text
            p._hoten = dtxt_hoten.Text
            p._sodienthoai = dtxt_sdt.Text
            p._diachi = dtxt_diachi.Text
            p._ghichu = dtxt_ghichu.Text
            p._ngaydk = de_dk.Value
            p._gioitinh = rdb_gioitinh.SelectedItem.Value
            If String.IsNullOrEmpty(Session("hinhanh").ToString()) Then
                p._hinh = String.Empty.ToString()
            Else
                p._hinh = "\img\user\" + Session("hinhanh")
                Session("hinhanh") = String.Empty
            End If
            docgia.DocGia_DK(p)
            successDiv.Attributes("class") = "alert alert-success"
            successDiv.Visible = True
            lb_mess.Text = "Thêm Thành Công"
            clearAllText()
        Catch ex As SqlException
            successDiv.Attributes("class") = "alert alert-warning"
            successDiv.Visible = True
            lb_mess.Text = If(String.IsNullOrEmpty(ex.Message), "Thêm Thất Bại", ex.Message)
        End Try
    End Sub
    Public Sub clearAllText()
        dtxt_taikhoan.Text = ""
        dtxt_rematkhau.Text = ""
        dtxt_hoten.Text = ""
        dtxt_sdt.Text = ""
        dtxt_diachi.Text = ""
        dtxt_ghichu.Text = ""
        rdb_gioitinh.SelectedItem.Value = -1
    End Sub

    Protected Sub upload_hinhdocgia_FileUploadComplete(ByVal sender As Object, ByVal e As DevExpress.Web.FileUploadCompleteEventArgs) Handles upload_hinhdocgia.FileUploadComplete
        Dim filename As String = e.UploadedFile.FileName
        e.UploadedFile.SaveAs(MapPath("~/img/user/") + filename)
        Session("hinhanh") = filename
        e.CallbackData = filename
    End Sub
End Class